package com.hxl.dailyworksummary.settings;

import com.intellij.util.ui.JBUI;

import javax.swing.*;
import java.awt.*;

public class AppSettingsComponent {
    private final JPanel panel = new JPanel();
    private final JTextField gitUsernameText = new JTextField();
    private final JPasswordField gitPasswordText = new JPasswordField();
    private final JTextField aiTokenText = new JTextField();

    public AppSettingsComponent() {
        panel.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();

        // Git Username
        gbc.insets = JBUI.insets(5);
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.anchor = GridBagConstraints.WEST;
        panel.add(new JLabel("Git Username:"), gbc);

        gbc.gridx = 1;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.weightx = 1.0;
        gitUsernameText.setPreferredSize(new Dimension(200, 25));
        panel.add(gitUsernameText, gbc);

        // Git Password
        gbc.fill = GridBagConstraints.NONE;
        gbc.weightx = 0.0;
        gbc.gridx = 0;
        gbc.gridy = 1;
        panel.add(new JLabel("Git Password:"), gbc);

        gbc.gridx = 1;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.weightx = 1.0;
        gitPasswordText.setPreferredSize(new Dimension(200, 25));
        panel.add(gitPasswordText, gbc);

        // AI Token
        gbc.fill = GridBagConstraints.NONE;
        gbc.weightx = 0.0;
        gbc.gridx = 0;
        gbc.gridy = 2;
        panel.add(new JLabel("AI Token:"), gbc);

        gbc.gridx = 1;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.weightx = 1.0;
        aiTokenText.setPreferredSize(new Dimension(200, 25));
        panel.add(aiTokenText, gbc);
    }

    public JPanel getPanel() {
        return panel;
    }

    public String getGitUsername() {
        return gitUsernameText.getText();
    }

    public void setGitUsername(String username) {
        gitUsernameText.setText(username);
    }

    public String getGitPassword() {
        return new String(gitPasswordText.getPassword());
    }

    public void setGitPassword(String password) {
        gitPasswordText.setText(password);
    }

    public String getAiToken() {
        return aiTokenText.getText();
    }

    public void setAiToken(String token) {
        aiTokenText.setText(token);
    }
}